﻿/// <reference path="RequestHandler.js" />
/// <reference path="../HttpRequest.js" />
/// <reference path="../../utilities/FXDom.js" />
/// <reference path="../../utilities/Markup.js" />
///--------------------------------------------------------------------
/// <file name="PrivateMessageHandler.js">
///   Adds markup buttons to the PM screen and applies
///   NAMFox preferences to the various check box options.
/// </file>
///--------------------------------------------------------------------

NAMFox.ns(function() { with (NAMFox) {

this.PrivateMessageHandler = function() {
};

PrivateMessageHandler.prototype = new RequestHandler();
PrivateMessageHandler.prototype.name = "PrivateMessageHandler";

PrivateMessageHandler.prototype.handleRequestCore = function(request, _$) {
    /// <summary>Handles a request.</summary>
    /// <param name="request" type="HttpRequest">
    ///   The HTTP request which encapsulates the
    ///   document and route data for this request.
    /// </param>

    var textArea = _$("#message");

    if (textArea.length === 1) {
        request.htmlDocument.__namfox__.textArea = textArea;

        if (!textArea.val()) {
            textArea.val($.messages.getDefaultMessage().text);
        }

        var privateMessages = $.getConfig().privateMessages;
        _$("#read_rcpt").attr("checked", privateMessages.readReceipt);

        _$("#editbuttons").append(
            Markup.create(
                textArea,
                MarkupLocation.PrivateMessage,
                Markup.strike,
                Markup.anchor,
                Markup.profile,
                Markup.privateMessageLink,
                Markup.replace,
                Markup.indent,
                Markup.superscript,
                Markup.subscript,
                Markup.code,
                Markup.php,
                Markup.pre,
                Markup.horizontalRule,
                Markup.videos,
                Markup.customMessages
            )
        );
    }
};

}});